package main

import (
	"fmt"
	"sync"
)

var lock = &sync.Mutex{}

type single struct {

}

var singleStance *single

func getInstance() *single {
	if singleStance == nil {
		lock.Lock()
		defer lock.Unlock()

		singleStance = &single{}
		fmt.Println("Creating single instance now.")
	} else {
		fmt.Println("Single instance already created.")
	}

	return singleStance
}

func main() {
	for i := 0; i < 30; i++ {
		go getInstance()
	}
}
